NeoVim

Keybinds and Remaps

Some ideas, idk
  • "while holding alt, I am in normal nvim".

Return to Normal Mode: some options
  • ctrl c

    • Works.

    • ctrl c now no longer closes tabs or the app.

  • qq

    • Works

  • alt qwer asd zx \

  • alt 1234

    • I found issues with this.

  • ~alt '

    • Works, but it's bad.

  • ~jj | kk | jk

    • Works but I hated it.

  • ctrl '

    • Doesn't work.

  • ctrl alt '

    • Doesn't work.

  • alt space

    • Can't do it.

  • ctrl space

    • Doesn't work.

  • shift space

    • Can't do it.

  • ctrl alt space

    • Can't do it.

Expression
  • expr = true

    • This allows the function return to be interpreted correctly as a command in Neovim.

Recursive and Non-Recursive
  • remap  is an option  that makes mappings work recursively. By default, it is on and I'd recommend you leave it that way. The rest are mapping commands , described below:

  • :map  and :noremap  are recursive  and non-recursive  versions of the various mapping commands. For example, if we run:

    :map j gg           (moves the cursor to the first line)
    :map Q j            (moves the cursor to the first line)
    :noremap W j        (moves the cursor down one line)
    
  • Then:

    • j  will be mapped to gg .

    • Q  will also  be mapped to gg , because j  will be expanded for the recursive mapping.

    • W  will be mapped to j  (and not to gg ) because j  will not be expanded for the non-recursive mapping.

  • For each of these sets of mappings, there is a mapping that works in normal, visual, select and operator modes ( :map  and :noremap ), one that works in normal mode ( :nmap  and :nnoremap ), one in visual mode ( :xmap  and :xnoremap ) and so on.

  • Mode letters:

    • n : normal only

    • v : visual and select

    • o : operator-pending

    • x : visual only

    • s : select only

    • i : insert

    • c : command-line

    • l : insert, command-line, regexp-search (and others. Collectively called "Lang-Arg" pseudo-mode)

Remove keybinds
  • You can't unmap  internal keybindings that vim needs but you can map them to <Nop>  to disable them.

    • <Nop>  is 'no operation'. It's a way to disable behavior.

  • "Try adding vim.keymap.del("n", "<leader>L")  to config/keymaps.lua ".

    • Maybe this only works with keybindings that are not internal.

  • Remove all default keybindings .

    • "Right now the solution is to map the items you want mapped and let them override the defaults, and any remaining defaults that you don't want to have you can map to "none" "

See shortcuts
  • Table with default shortcuts .

  • :map

    • Only shows user or plugin remaps.

    • :nmap  for normal mode mappings

    • :vmap  for visual mode mappings

    • :imap  for insert mode mappings

  • :Telescope keymaps

    • Only shows user or plugin remaps.

  • Keyseer .

    • :KeySeer

Modifier Keys
  • Ctrl

    • <C>

    • <D>

  • Shift

    • <S>

  • Alt

    • <M>

    • <A>

Special Keys
  • Enter

    • <Enter>

    • <Return>

    • <CR>

  • Esc

    • <Esc>

  • Backspace

    • <BS>

  • Tab

    • <Tab>

  • Space

    • <Space>

  • Delete

    • <Del>

  • Up Arrow

    • <Up>

  • Down Arrow

    • <Down>

  • Left Arrow

    • <Left>

  • Right Arrow

    • <Right>

  • Beginning of line

    • <Home>

  • End of line

    • <End>

  • PageUp

    • <PageUp>

  • PageDown

    • <PageDown>

Basics

Open NVim
  • nvim .

    • opens nvim in the current directory, showing a list of folders

    • by default, the file structure is shown with NetRW, a file manager from nvim

  • nvim file_name.lua

    • opens the given file in nvim

Help
Commands
  • :

    • nvim command

  • :!

    • external commands

  • @:

    • repeat last ex command

  • @@

    • after repeating it once, you can continue repeating with this

  • ctrl d

    • while typing a command, ctrl d will show a list of commands that completes the one you're typing

    • use tab to scroll through the completions

Terminal
[  ]

Interface

  • A buffer is an in-memory text of a file.

  • A window is a viewport on a buffer.

  • A tab page is a collection of windows.

  • Explanation .

Editor

Zoom
  • ctrl -

    • zoom out

  • ctrl =   or ctrl +

    • zoom in

  • ctrl 0

    • reset zoom

Buffer

Buffers
  • :buffers

    • lists open buffers

  • LeaderLeader

    • lists open buffers via Telescope

Quickfix

Window

Window Splits
  • ctrl w ctrl w

    • moves from one window to another

    • :q closes only the selected tab, be careful when using this

Tab

  • .

Session

Default
  • Explanation .

  • :mksession [path]

    • Save a .vim file.

  • source [path]

  • Closing nvim without saving the session will not automatically save it.

    • It's mentioned about maybe using the BufWinLeave  event to auto-save.

  • The session can be opened outside of nvim using nvim -S [path] .

FileSystem

Exit
  • :q

    • quits if no change is made

    • This fails when changes have been made and Vim refuses to abandon the current buffer, and when the last file in the argument list has not been edited.

    • If there are other tab pages and quitting the last window in the current tab page, the current tab page is closed.

    • Triggers the |QuitPre| autocommand event.

    • :q!   ||   ZQ

      • Force quit, discarding changes.

Save
  • :w

    • write changes, saving the file.

    • if the file doesn't exist, a name can be given.

    • :w Test

      • saves the file as Test

    • :w!

      • Like ":write", but forcefully writes when 'readonly' is set or there is another reason writing was refused.

      • Note: This may change permissions and ownership of the file and break (symbolic) links.  Add the 'W' flag to 'cpoptions' to avoid this.

  • :x  ||  ZZ

    • write changes and quit.

    • :wq

      • Doesn't work if the file is readonly.

    • :wq!

      • Force to write the file and quit after saving.

Create
  • :e

    • ~creates a file or edits an existing one.

      • I interpret as touch

    • Pathing is always based on the terminal cd , usually in $HOME .

Delete
  • :!del

    • deletes a file

    • It's an external command.

    • :!del Test

      • deletes the file Test

Info
  • :f

    • name of the current file

    • :f new_name.lua

      • rename the file to the given name.

    • edits the given file

      • :fin file_name.lua

      • :e file_name.lua

  • :!dir

    • list your directory

    • It's an external command.

  • :ls  ||  :files

    • list files

NetRW
  • Tutorial .

  • :Ex  |  :Explore

    • goes back to NetRW if inside a file

Movement

Info
Tips
  • Tips .

    • Good video, very complete.

  • diw and diW .

  • Vertical .

    • Keep the cursor in the center of the screen while doing pageup and pagedown

      • nnoremap("<C-d>", "<C-d>zz")

      • nnoremap("<C-u>", "<C-u>zz")

  • Horizontal .

  • Tips 1 .

    • Don't use hjkl.

    • Don't use f, F, t, or T too often as it requires ; or , to advance to where you want.

    • Use viw or viW more often, etc.

    • He prefers:

      • VD instead of dd.

      • VY instead of yy.

    • Use xnoremap("<leader>p", "\"_dP")  to "fix" Put behavior, so it doesn't store the previously selected text during Put.

      • That is, it makes the behavior similar to Ctrl V on Windows.

  • Tips 2 .

    • 'ctrl d' and 'ctrl u' are disorienting, but useful after a while.

Practice
Movement
  • $ hjkl

    • movement

  • $ M

    • set cursor to the middle

Movement: Vertical
  • Line

    • :30

      • goes to line 30

    • 30

      • advances 30 lines

        • beginning of the line above

        • beginning of the line below

  • Scroll:

    • ctrl e

      • scroll down

    • ctrl y

      • scroll up

    • /NUM%

      • go to a % of the file

  • Page

    • ctrl d

      • page down

    • ctrl u

      • page up

  • File

    • gg

      • go to start of the file

    • G

      • go to bottom of the file

      • 450G

        • go to line 450

      • 450gg

        • go to line 450

Movement: Horizontal
  • Paragraphs

    • {

      • up paragraph

    • }

      • down paragraph

  • Line

    • 0

      • BOL

    • |

      • BOL

    • _

      • BOL, without spaces or tabulation

    • $

      • EOL

    • g_

      • EOL, without spaces or tabulation

  • Word:

    • w

      • next word

      • 3w

        • 3 words forward

    • W

      • next WORD

    • b

      • previous word

      • 3b

        • 3 words back

    • % B

      • previous WORD

    • % e

      • end of the next word

      • 2e

        • end of 2 words forward

    • % E

      • end of the next WORD

    • % ge

      • end of the previous word

    • % ge

      • end of the previous WORD

  • Char

    • % f{char}

      • find char to the right

      • fy

        • find the first char y to the right of the cursor

    • % F{char}

      • find char to the left

      • Fy

        • find the first char y to the left of the cursor

    • % t{char}

    • % T{char}

    • $ ;

      • repeat latest f, F, t, T

    • $ ,

      • repeat latest f, F, t, T in the opposite direction

  • /

    • /somename

      • searches for somename

      • pressing Enter ends the search

      • pressing n goes to the next result

      • pressing N goes to the previous result

  • ?

    • ?somename

      • searches for somename in the opposite direction

      • pressing Enter ends the search

      • pressing n goes to the next result

      • pressing N goes to the previous result

  • *

    • next occurrence of the hovered word

      • stores the word in the / search

  • #

    • previous occurrence of the hovered word

      • stores the word in the ? search

  • % (while inside a parenthesis)

    • goes to its pair

Jumps
  • :ju

    • sees the jump list

  • :cle

    • clears the jump list

  • $ ctrl o

    • older position in a jump list

  • $ ctrl i

    • newer position in a jump list

Marks
  • '{char}

    • go to mark

    • ' '

      • toggle between recent marks

  • % "{char}

    • register a mark

  • $ m

    • register a mark

  • :delmarks A-Z0-9

    • Note: ~/.viminfo  contains histories and marks, if you don't want them anymore, you can delete this file. Vim will recreate it next time.

Registers
  • $ "{char}

    • go to registers

Telescope
  • esc

    • close

  • $ ctrl c

    • close

  • ?

    • Keymap help.

  • Selection :

    • Scroll selection:

      • Insert mode:

        • tab

          • scroll up

        • shift tab

          • scroll down

        • ctrl n

          • scroll down

        • ctrl p

          • scroll up

      • Normal mode:

        • tab

          • scroll up

        • shift tab

          • scroll down

        • ctrl n

          • scroll down

        • ctrl p

          • scroll up

        • j

          • scroll down

        • k

          • scroll up

    • Open:

      • About .

      • ctrl t

        • open as a new tab

      • ctrl x

        • open as a horizontal split

      • ctrl v

        • open as a vertical split

  • Preview :

    • Scroll:

      • ctrl d

        • scroll down

      • ctrl u

        • scroll up

      • ctrl f

        • scroll left

      • ctrl k

        • scroll right

Operations

Duplication
  • duplicate operator to act on current line.

    • dd

      • delete line

    • yy

      • yank line

    • >>

      • indent line

    • ==

      • format line

Insertion
  • a

    • (append)

    • text after the cursor

  • A

    • (insert)

    • text at the end of the line

  • % i

    • (insert)

    • text before the cursor

  • I

    • (insert)

    • text at the beginning of the line

  • c

    • (change)

    • ce

      • deletes until the end of the word and goes to insert mode.

    • c$

      • deletes until the end of the line and goes to insert mode.

  • o

    • (open)

    • text in the line below

  • O

    • (open)

    • text in the line above

  • % r

    • (replace)

    • rx

      • replace the char with x

    • rr

      • replace the char with r

  • $ R

    • (replace)

    • replaces all the following chars

    • R1235566

      • replaces all the following chars with 1235566

Visual Selection
  • v

    • (visual selection mode)

    • selects text

    • if : is pressed, it's going to type :'<,'>  automatically. You can type commands after this line of code, to only affect the selection

  • V

    • visual selection lines mode

    • select lines

  • ctrl v

    • visual selection block mode

Substitute
  • :s/thee/the

    • substitute thee for the, only the first apperance

    • :s/thee/the/g

      • substitute thee for the whole line

    • :%s/thee/the/g

      • substitute thee for the whole file

    • :%s/thee/the/gc

      • substitute thee for the whole file, with a prompt asking if should substitute

Delete
  • x

    • delete char

  • X

    • delete previous char

  • d

    • dw

      • delete word

      • d3w

        • deletes 3 words

    • de

      • delete until the end of the current word

    • d$

      • delete until the end of the line

    • dd

      • delete line

      • 2dd

        • deletes 2 lines

Yank (Copy)
  • y

    • copy text

    • leaves the visual mode, if it's in it

  • Y

    • copy the text from the cursor to the end of the line

Put (Paste)
  • p

    • puts the previously deleted text after  the cursor.

  • P

    • puts the previously deleted text before  the cursor.

Undo
  • u

    • undo

  • $ U

    • undo the whole line to its original state

  • $ ctrl r

    • redo

Casing
  • $

    • swap case

  • g

    • swap case in the whole line

  • gu

    • make lowercase

  • gU

    • make uppercase

Formatting
  • ==

    • text formatting

Folding
  • zf

    • zf5j

      • creates a folding region for the 5 lines below